/*******************************************************
> Copyright (C) 2024 ==IOT== All rights reserved.
> File Name: 创建一个子进程.c
> Author: lv1
> Website:www.lv1.org
> Created Time: 2024年08月03日 星期六 11时24分17秒
***************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, const char* argv[])
{
	pid_t pid;
	pid = getpid();
	printf("这是第一次getpid的结果：%d\n",pid);
	pid = fork();
	int i = 0 , j = 0 , k = 0;
	if(pid == 0){
		while(i<5){
		printf("这是子1进程：%d\n",getpid());
		i++;
		sleep(1);
		}
		exit(0);
	}
	pid = fork();
	if(pid == 0){
		while(j<5){
		printf("这是子2进程：%d\n",getpid());
		j++;
		sleep(1);
		}
		exit(0);
	}
	else if(pid>0){
		while(k<5){
		printf("这是父进程:%d\n",getpid());
		k++;
		sleep(1);
	}
	}
    return 0;
}
